﻿//
// (C) Copyright 2009 Irantha Suwandarathna (iranthas@hotmail.com)
// All rights reserved.
//

/********************************************************
 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
 * Written by Robert Simpson (robert@blackcastlesoft.com)
 * 
 ********************************************************/


using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using EffiProzDB;

namespace System.Data.EffiProzDB
{
    public sealed class EffiProzDBException : DbException
    {
       // private string _sqlState;

      
        /// <summary>
        /// Various public constructors that just pass along to the base Exception
        /// </summary>
        /// <param name="message">Passed verbatim to Exception</param>
        public EffiProzDBException(string message)
            : base(message)
        {
        }

        // <summary>
        /// Various public constructors that just pass along to the base Exception
        /// </summary>
        /// <param name="message">Passed verbatim to Exception</param>
        public EffiProzDBException(string message, string sqlState, int errorCode)
            : base(message, errorCode)
        {
        }

        /// <summary>
        /// Various public constructors that just pass along to the base Exception
        /// </summary>
        public EffiProzDBException()
        {
        }

        /// <summary>
        /// Various public constructors that just pass along to the base Exception
        /// <param name="message">Passed to Exception</param>
        /// <param name="innerException">Passed to Exception</param>
        /// </summary>
        public EffiProzDBException(string message, Exception innerException)
            : base(message, innerException)
        {
        }



        public static void throwError(HsqlException e)
        {
            throw new EffiProzDBException(e.getMessage(), e.getSQLState(),
                                   e.getErrorCode());
        }

        public static void throwError(Result r)
        {
            throw new EffiProzDBException(r.getMainString(), r.getSubString(),
                                   r.getStatementID());
        }

        public static EffiProzDBException GetException(HsqlException e)
        {
            return new EffiProzDBException(e.getMessage(), e.getSQLState(),
                                    e.getErrorCode());
        }


        public static EffiProzDBException GetException(int id)
        {
            return GetException(Trace.error(id));
        }

        public static EffiProzDBException GetException(int id, String message)
        {
            return GetException(Trace.error(id, message));
        }

        public static EffiProzDBException GetException(int id, int subId, Object[] add)
        {
            return GetException(Trace.error(id, subId, add));
        }

        public static EffiProzDBException notSupported()
        {
            return GetException(Trace.error(Trace.FUNCTION_NOT_SUPPORTED));
        }

        public static EffiProzDBException nullArgument()
        {
            return GetException(Trace.INVALID_ADO_ARGUMENT);
        }

        static EffiProzDBException nullArgument(String name)
        {
            return GetException(Trace.INVALID_ADO_ARGUMENT, name + ": null");
        }

        public static EffiProzDBException invalidArgument()
        {
            return GetException(Trace.INVALID_ADO_ARGUMENT);
        }

        public static EffiProzDBException invalidArgument(String name)
        {
            return GetException(Trace.INVALID_ADO_ARGUMENT, name);
        }

        public static EffiProzDBException outOfRangeArgument()
        {
            return GetException(Trace.INVALID_ADO_ARGUMENT);
        }

        public static EffiProzDBException outOfRangeArgument(String name)
        {
            return GetException(Trace.INVALID_ADO_ARGUMENT, name);
        }

        public static EffiProzDBException connectionClosedException()
        {
            return GetException(Trace.CONNECTION_IS_CLOSED);
        }
    }
}
